/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { processOptions } from './utils';
import beacon from './beacon';

class ReportClick {
  public el: any;
  public frozen = false;
  public options = null;
  public callback: any;
  public oldResult = null;
  public eventCode = '';
  public direct = false;
  public params = {};
  public constructor(el: any, binding: { value: any }, vnode: any) {
    const { value } = binding;
    this.el = el;
    this.frozen = false;
    this.eventCode = value.EventCode;
    this.direct = value.Direct;
    this.params = value.Params || {};
    this.doReport(value, vnode);
  }

  public doReport(options: any, vnode: any) {
    if (this.frozen) return;

    this.options = processOptions(options);

    this.callback = (...args: any) => {
      beacon.report(this.eventCode, this.params, this.direct);
    };

    this.el.addEventListener('click', () => {
      this.callback();
    });
  }
}

const beforeMount = (el: any, binding: any, vnode: any) => {
  new ReportClick(el, binding, vnode);
};

export default {
  beforeMount,
};
